"""
2. 已知一个列表为 nums = [1,0,-1,-2,-3,2,3 ]，target = 0 ，找到所有的满足数组内三个数相加等于target的组合，不能使用穷举法。
"""
import copy


def find_out_combinations(nums, target):

    xset = set()

    def judge(xtuple):
        xtuple = tuple(sorted(xtuple))
        if xtuple in xset:
            return True
        else:
            xset.add(xtuple)
            return False

    nums = list(nums)
    for i in range(len(nums)):
        xcopy = copy.deepcopy(nums)
        first = xcopy.pop(i)
        for j in range(len(xcopy)):
            xcopy02 = copy.deepcopy(xcopy)
            second = xcopy02.pop(j)
            for third in xcopy02:
                if target == first + second + third:
                    if judge((first, second, third, )):
                        continue
                    yield first, second, third


if '__main__' == __name__:

    def main():
        nums = [1, 0, -1, -2, -3, 2, 3]
        target = 0
        result_gen = find_out_combinations(nums, target)
        for result in result_gen:
            print(result)

    main()
